﻿using System;

namespace ErgoBreak.Core
{
    internal abstract class ObserverBase
    {
        #region Fields
        protected ObservationStatus status;
        #endregion

        #region Events
        /// <summary>
        /// Occurs when a break event has to happen. 
        /// </summary>
        public event BreakEventHandler BreakProposed;
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes an instance of ObserverBase.
        /// </summary>
        public ObserverBase()
        {
            this.status = ObservationStatus.Active;
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the status of current observation.
        /// </summary>
        public ObservationStatus Status
        {
            get { return this.status; }
        }

        /// <summary>
        /// Gets the remaining time to the next break.
        /// </summary>
        public abstract int TimeRemainedToBreak
        {
            get;
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Continues the normal procedure after 'Suspend' or 'TurnOff' is called, or 
        /// a break has been occured.
        /// </summary>
        public abstract void Continue();
        
        /// <summary>
        /// Puts the observation on hold until 'Continue' is called.
        /// </summary>
        public abstract void Suspend();

        /// <summary>
        /// Turns the observation off until 'Continue' is called. It should be noted
        /// that this is different from 'Suspend' method.
        /// </summary>
        public abstract void TurnOff();
        #endregion

        #region Non-Public Methods
        protected void OnBreakBegins(int proposedTime)
        {
            if (this.BreakProposed != null)
            {
                Suspend();
                BreakProposed(this, new BreakEventArgs(new Break(proposedTime, BreakStatus.Proposed)));
            }
        }

        protected void SetStatus(ObservationStatus status)
        {
            this.status = status;
        }
        #endregion
    }
}
